<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/cookie.js"></script>
    <script type="text/javascript" src="/static/js/http.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>

    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
          <!--  
          <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
          <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
          -->
          <span>请输入时间</span>
          <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
          <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
          <input class="layui-input"  autocomplete="off" placeholder="关键字" name="key" >
          
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      
      <div>
        <button class="layui-btn" onclick="x_admin_show('添加用户','log-add.html',600,400)"><i class="layui-icon"></i>添加</button>
      </div>
      <div>
      	<table id="myTable" class="layui-table x-admin" lay-filter="table_a"></table>
      </div>
      

    </div>
    
	<script type="text/html" id="barDemo">
			<!-- 表格每行操作模板 -->
			<!--  laytpl 模板语法 -->
            <a title="编辑"  lay-event="edit">
            	<i class="layui-icon">&#xe642;</i>
            </a>
            <a title="删除"  lay-event="del">
                <i class="layui-icon">&#xe640;</i>
            </a>
  	
	</script>
    
    <script>
      layui.use(['table','form','laydate'], function(){
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        
        laydate.render({
          elem: '#start' //指定元素
        });
        laydate.render({
            elem: '#end' //指定元素
        });
		var WHERE = {
				
		};
        
		/*表格组件*/
		table.render({
			id: 'myTable',
			elem: '#myTable',
			height: 500,
			page: true,
			url: '/admin/qz/list?token='+new Date().getTime(),
			method: 'post',
			request: {
				/*固定参数：页数，每页多少条*/
				pageName: 'pageNum',
				limitName: 'pageSize'
			},
			where: WHERE, //附加参数
			parseData: function(res) {
			
				if(!canDoNext(res)){
					return ;
				}
				/*返回数据解析*/
				return {
					'code': res.code,
					'msg': res.msg,
					'count': res.data.totalRow,
					'data': res.data.list
				}

			},
			response: {
				/*将返回字段对应成table组件使用格式*/
				statusName: 'code',
				statusCode: 1000,
				msgName: 'msg',
				countName: 'count',
				dataName: 'data'
			},
			done:function(res,curr,page){
				
			},
			cols: [ //表结构
				[ {
					field: 'id',
					title: 'ID',
				},
				{
                    field: 'request',
                    title: '操作'
                },
                {
                    field: 'account',
                    title: '姓名'
                },
                {
                    field: 'name',
                    title: '姓名'
                },
                {
                    field: 'result',
                    title: '返回结果'
                },
                {
                    field: 'boxId',
                    title: '操作盒子ID'
                },
                
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'updateTime',
                    title: '修改时间'
                },
				{
					fixed: 'right',
					align: 'left',
					toolbar: '#barDemo',
					width: 500
				}]
			]
		});
		
		
		
		/*单行操作*/
		table.on('tool(table_a)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
			var data = obj.data; //获得当前行数据
			var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
			var tr = obj.tr; //获得当前行 tr 的DOM对象
			if(layEvent === 'edit') {
				x_admin_show('编辑','member-edit.html',600,400,data.id);
			}else if(layEvent === 'del') {
				
				   layer.confirm("确认要删除吗，删除后不能恢复", { title: "删除确认" }, function (index) {
		               mPost("../static/sys/delete", data,function(res) {
		                    if(res.code == 1000) {
		                    	 layer.close(index); //如果设定了yes回调，需进行手工关闭
		                    	 reloadTable();
		                    } else {
		                        alert(res.msg);
		                    }
		                },this);
					  
				   });
		                	
			}else if(layEvent === 'reset'){
				
	               layer.confirm("确认要重置密码么，重置密码后密码为123456", { title: "删除重置" }, function (index) {
                       mPost("../static/sys/reset", data,function(res) {
                            if(res.code == 1000) {
                            	reloadTable();
                                 layer.close(index); //如果设定了yes回调，需进行手工关闭
                            } else {
                                alert(res.msg);
                            }
                        },this);
                      
                   });
			}
		});
		
	      var user = localStorage.getItem("user");
	      var  userRole=1;
	      if(user){
	          user = JSON.parse(user);
	        if('admin'==user.name){
	            var html=" <a title='重置'  lay-event='reset'><i class='layui-icon'>&#xe669;</i></a>";
	            userRole=0;
	               $("#barDemo").append(html);
	             
	        }
	      }
		
	      //监听查询
	      form.on('submit(sreach)', function(data){
	          WHERE = data.field;
	          reloadTable();
	          return false;
	      });
	      
	      
	      /*重载刷新列表*/
	      function reloadTable() {
	          layer.load(3, {
	                  shade: [0.2, '#000']
	              })
	              /*表格携带参数发送请求重载*/
	          table.reload('myTable', {
	              where: WHERE,
	              page: {
	                  curr: 1
	              }
	          })
	          layer.closeAll('loading')
	      }
       
        
      });

    

     
    </script>
  </body>

</html>